package com.lzs.kunei.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzs.entity.Allocation;
import com.lzs.kunei.mapper.AllocationMapper;
import com.lzs.kunei.service.AllocationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzs.util.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wpy
 * @since 2020-11-24
 */
@Service
public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocation> implements AllocationService {
    @Autowired
    private AllocationMapper allocationMapper;
    @Override
    public Page<Allocation> selectAllocationPage(Integer current, Integer size, Allocation allocation,String[] warehouseid) {
        Page<Allocation> allocationPage=new Page<>(current,size);
        String allocationno = allocation.getAllocationno();

        String state = allocation.getState();
        QueryWrapper<Allocation> queryWrapper=new QueryWrapper<>();
        queryWrapper.in("bwarehouseid",warehouseid);

        if (StringUtils.isNotEmpty(allocationno)){
            queryWrapper.like("allocationno",allocationno);
        }

        if (StringUtils.isNotEmpty(state)){
            queryWrapper.like("state",state);
        }
        allocationMapper.selectPage(allocationPage,queryWrapper);
        return allocationPage;
    }


    @Override
    public R updateAudit(String state, List<Long> list) {
        int i=-1;
        if (list!=null&&list.size()>0){
            i = allocationMapper.updateAudit(state, list);
        }
        if (i!=-1){
            return R.ok().message("操作成功");
        }else {
            return R.error().message("操作成功");
        }
    }
}
